﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace FooFun.DataElements.Dtos
{
    public class DataTableDataElement : DataElement
    {
        DataTable dt;

        public DataTableDataElement(DataTable dt)
        {
            this.dt = dt;
        }

        #region IDataElement 成员

        public override object Value
        {
            get
            {
                return dt;
            }
            set
            {
                dt = (DataTable)value;
            }
        }

        public override IDataElement this[int index]
        {
            get
            {
                return new DataRowDataElement(this.dt.Rows[index]);
            }
            set
            {
                base[index] = value;
            }
        }

        public override bool IsEmpty
        {
            get
            {
                return this.dt.Rows.Count == 0;
            }
        }

        #endregion

        #region IEnumerable 成员

        public override System.Collections.IEnumerator GetEnumerator()
        {
            foreach (DataRow row in dt.Rows)
            {
                yield return new DataRowDataElement(row);
            }
        }

        #endregion
    }

   
}
